#include "mylabel.h"
#include <QDebug>
#include <QMouseEvent>

myLabel::myLabel(QWidget *parent) : QLabel(parent)
{
    setMouseTracking(true);
}

void myLabel::enterEvent(QEvent *event)
{
    // qDebug()<<"鼠标进入了";
}

void myLabel::leaveEvent(QEvent *event)
{
    //qDebug()<<"鼠标离开了";
}

void myLabel::mouseMoveEvent(QMouseEvent *ev)
{
    //if(ev->buttons()&Qt::MouseButton::LeftButton) {
        QString str = QString("鼠标移动了 x=%1, y=%2, globalX=%3, globalY=%4" )
                .arg(ev->x()).arg(ev->y())
                .arg(ev->globalX()).arg(ev->globalY());
        qDebug()<<str;
    //}
}

void myLabel::mousePressEvent(QMouseEvent *ev)
{
    if(ev->button()==Qt::MouseButton::LeftButton) {
        QString str = QString("鼠标按下了 x=%1, y=%2, globalX=%3, globalY=%4" )
                .arg(ev->x()).arg(ev->y())
                .arg(ev->globalX()).arg(ev->globalY());
        qDebug()<<str;
    }
}

void myLabel::mouseReleaseEvent(QMouseEvent *ev)
{

    if(ev->button()==Qt::MouseButton::LeftButton) {
        QString str = QString("鼠标释放了 x=%1, y=%2, globalX=%3, globalY=%4" )
                .arg(ev->x()).arg(ev->y())
                .arg(ev->globalX()).arg(ev->globalY());
        qDebug()<<str;
    }
}

bool myLabel::event(QEvent *e)
{
    if(e->type()==QEvent::MouseButtonPress) {
        QMouseEvent *ev = static_cast<QMouseEvent*>(e);
        QString str = QString("Event 鼠标按下了 x=%1, y=%2, globalX=%3, globalY=%4" )
                .arg(ev->x()).arg(ev->y())
                .arg(ev->globalX()).arg(ev->globalY());
        qDebug()<<str;
        return true;
    }

    return QLabel::event(e);
}
